package sample;

import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

import java.io.File;
import java.util.List;

public class Main extends Application {
	@FXML
	private Button inputFileBtn;//输入文件选择按钮
	@FXML
	private Button inputDirectoryBtn;//输入目录选择按钮
	@FXML
	private Button outputBtn;//输出目录选择按钮
	@FXML
	private TextField inputField;//输入路径
	@FXML
	private TextField outputField;//输出路径
	Stage stage;

    @Override
    public void start(Stage stage) throws Exception{
    	this.stage = stage;
        Parent root = FXMLLoader.load(getClass().getResource("main.fxml"));
	    stage.setTitle("Hello World");
	    stage.setScene(new Scene(root, 522, 442));
	   // Controller controller = new Controller(stage);

	    System.out.println(inputFileBtn);
	    /*inputFileBtn.setOnMouseClicked(event ->{
		    FileChooser fc = new FileChooser();
		    fc.setTitle("选择文件");
		    fc.selectedExtensionFilterProperty();
		    fc.getExtensionFilters().addAll(
				    new FileChooser.ExtensionFilter("All", "*.*")
		    );
		    List<File> list =  fc.showOpenMultipleDialog(stage);
		    StringBuilder sb = new StringBuilder();
		    list.forEach(item ->{
			    sb.append(item.getName()).append(",");
		    });
		    inputField.setText(sb.toString().substring(0,sb.length()-1));
	    });

	    inputDirectoryBtn.setOnMouseClicked(event ->{
		    inputField.setText(showDialog());
	    });

	    outputBtn.setOnMouseClicked(event->{
		    outputField.setText(showDialog());
	    });*/
	    stage.show();
    }

	private String showDialog(){
		DirectoryChooser dc = new DirectoryChooser();
		dc.setTitle("选择目录");
		File directory = dc.showDialog(stage);
		return directory.getAbsolutePath();
	}

    public static void main(String[] args) {
        launch(args);
    }
}
